const express = require("express");
const router = express.Router();
const workValidate = require("../middleware/workValidate");
const { verifyRole } = require("../middleware/role");
const workContorller = require("../contorller/workContorller");
const { verifyToken } = require("../middleware/jwt");
router
  //创建作品
  .post(
    "/create",
    verifyToken(),
    workValidate.createWorkValidate,
    verifyRole("work"),
    workContorller.createWork
  )
  //获取作品(个人)
  .get(
    "/getMyWorkList",
    verifyToken(),
    // verifyRole("work"),
    workContorller.getMyWorkList
  )
  //获取个人作品详情
  .get(
    "/getMyWorkDetail",
    workValidate.getWorkDetailValidate,
    verifyToken(),
    verifyRole("work"),
    workContorller.getMyWorkDetail
  )
  //获取作品详情
  .get("/getWorkDetail", verifyToken(), workContorller.getWorkDetail)
  .get(
    "/getTemplateList",
    verifyToken(false),
    workContorller.getTemplateWorkList
  )
  .patch(
    "/updateWork",
    workValidate.updateWorkValidate,
    verifyToken(),
    verifyRole("work"),
    workContorller.updateWork
  )
  .delete(
    "/deleteWork",
    workValidate.deleteWorkValidate,
    verifyToken(),
    verifyRole("work"),
    workContorller.deleteWork
  )
  .post(
    "/publishWorkOrTemplate",
    workValidate.publishWorkValidate,
    verifyToken(),
    verifyRole("work", { action: "publish" }),
    workContorller.publishWorkOrTemplate
  )
  //复制作品
  .get("/copyWork", verifyToken(), workContorller.copyWork)
  //创建渠道
  .post(
    "/createChannel",
    workValidate.createChannelValidate,
    verifyToken(),
    verifyRole("work", {}, "channel"),
    workContorller.createChannel
  )
  //获取作品渠道列表
  .get(
    "/channelList/:workId",
    verifyToken(),
    verifyRole("work"),
    workContorller.getChannelList
  )
  //修改作品渠道
  .patch(
    "/updateChannel/:channelId",
    workValidate.updateChannelValidate,
    verifyToken(),
    verifyRole("work", { channel: true }, "channel"),
    workContorller.updateChannelName
  )
  //删除作品渠道
  .delete(
    "/deleteChannel/:channelId",
    verifyToken(),
    verifyRole("work", { channel: true }, "channel"),
    workContorller.deleteChannel
  );

module.exports = router;
